package com.tutorial.demo.fileDemo;

import java.io.File;

public class FileDemo1 {
    public static void main(String[] args) {
        //显示当前程序的main文件夹下有哪些子文件夹及文件
        String path = "src/main";
        showFiles(path);
    }

    public static void showFiles(String path){
        File file = new File(path);
        String seperator = "";
        System.out.println(file.getName());
        showFiles(file,seperator);
    }

    private static void showFiles(File file,String seperator){
        if(file.isFile()){
            System.out.println(seperator + file.getName());
            return;
        }
        File[] childFiles = file.listFiles();
        seperator +=" ";
        for (int i = 0; i < childFiles.length; i++) {
            System.out.println(seperator+"--" + childFiles[i].getName());
            showFiles(childFiles[i],seperator);
        }
    }
}
